import { CDHuangXiaoxiDialogue } from "../excel/CDHuangXiaoxiDialogue";

/**
 * 黄小西对话
 */
export class CEHuangXiaoxiDialogue {
    /** 获取随机对话 */
    /**
     * 
     * @param dialogueType 对话类型
     * @param chapter 章节
     * @returns 
     */
    public static getRandomDialogue(dialogueType: number, chapter: number=0): CDHuangXiaoxiDialogue {
        if (!CDHuangXiaoxiDialogue.datas) return null;

        const allDialogues = CDHuangXiaoxiDialogue.datas.getValues();
        let matchingDialogues: CDHuangXiaoxiDialogue[] = [];
        if (dialogueType === 0) {
            return allDialogues[Math.floor(Math.random() * allDialogues.length)];
        } else if (dialogueType === 1) {
            matchingDialogues = allDialogues.filter(d => d.dialogueType === dialogueType);
        } else {
            matchingDialogues = allDialogues.filter(d => d.dialogueType === dialogueType && d.chapter === chapter);
        }

        if (matchingDialogues.length === 0) return null;

        const randomIndex = Math.floor(Math.random() * matchingDialogues.length);
        return matchingDialogues[randomIndex];
    }
    /**
     * 获取随机喊话类型
     * @param chapter 章节
     * @returns 
     */
    public static getRandomDialogueType(chapter: number=0): number {
        let dialogueType = Math.ceil(Math.random() * 2);
        const dialogue = this.getRandomDialogue(dialogueType, chapter);
        return dialogue.desc;
    }
}
